package com.rongshu.sendmessage.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.rongshu.sendmessage.R;
import com.rongshu.sendmessage.bean.PayLogBean;

import java.util.List;

public class PayLogAdapter extends BaseAdapter {
    private final Context mContext;
    private final List<PayLogBean> mList;
    private final LayoutInflater mInflater;

    public PayLogAdapter(Context context, List<PayLogBean> list) {
        mContext=context;
        mList=list;
        mInflater= LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return mList.size();
    }

    @Override
    public Object getItem(int position) {
        return mList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        Houdle houdle;
        if (convertView==null){
            houdle=new Houdle();
            convertView=mInflater.inflate(R.layout.pay_log_item,null);
            houdle.tv_title=convertView.findViewById(R.id.tv_title);
            houdle.tv_order_id=convertView.findViewById(R.id.tv_order_id);
            houdle.tv_pay_type=convertView.findViewById(R.id.tv_pay_type);
            houdle.tv_pay_time=convertView.findViewById(R.id.tv_pay_time);
            houdle.tv_pay_money=convertView.findViewById(R.id.tv_pay_money);
            houdle.tv_pay_state=convertView.findViewById(R.id.tv_pay_state);
            convertView.setTag(houdle);
        }else{
            houdle= (Houdle) convertView.getTag();
        }
        PayLogBean payLogBean = mList.get(position);
        houdle.tv_pay_money.setText(payLogBean.getAmountYuan());
        houdle.tv_pay_state.setText(payLogBean.getPayStateStr());
        houdle.tv_pay_time.setText(payLogBean.getCreateTime());
        houdle.tv_pay_type.setText(payLogBean.getPaymentMethod());
        houdle.tv_order_id.setText("订单编号："+payLogBean.getOrderNo());
        if ("支付成功".equals(payLogBean.getPayStateStr())){
            houdle.tv_pay_state.setTextColor(mContext.getResources().getColor(R.color.bg_green));
        }else {
            houdle.tv_pay_state.setTextColor(mContext.getResources().getColor(R.color.gray_color));
        }
        return convertView;
    }
    class Houdle{

        public TextView tv_title,tv_pay_type,tv_pay_time,tv_pay_money,tv_pay_state;
        public TextView tv_order_id;
    }
}
